﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Hengbei.Web.Admin
{
    public partial class RoleManage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void dvRole_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
        {
            gvRoles.DataBind();
        }

        protected void gvRoles_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            AddConfirmDelete((GridView)sender, e);
        }

        /// <summary>
        /// If the gridview has a command field where showdeletebutton is true, then 
        /// it add a confirm message. 
        /// This function should be called in the RowDataBound event
        /// </summary>
        public static void AddConfirmDelete(GridView gv, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                foreach (DataControlField dcf in gv.Columns)
                {
                    if (dcf.ToString() == "CommandField")
                    {
                        if (((CommandField)dcf).ShowDeleteButton == true)
                        {
                            e.Row.Cells[gv.Columns.IndexOf(dcf)].Attributes
                            .Add("onclick", "return confirm(\"确认要删除该条记录吗？\")");
                        }
                    }
                }
            }
        }
    }
}